	//
	//  GaoTvcLl.m
	//  GaoDisplayManagerDemo
	//
	//  Created by Gikki Ares on 2020/8/5.
	//

#import "JsTvcLll.h"
#import "JsGeometryManager.h"
@interface JsTvcLll()
{
	JsTvcLllModel * mModel;
}
@end

@implementation JsTvcLll

- (void)awakeFromNib {
	[super awakeFromNib];
//	[self setupUi];
		// Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
	if(self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
		[self commonInit];
	}
	return self;
}

- (void)commonInit {
	
}

- (void)setupUi:(JsTvcLllModel *)model {
	CGFloat padding = model.commonStyle.paddingV;
	JsTvcLllStyle * style = model.commonStyle;
	{
		if(!_mLb_index) {
			_mLb_index = [UILabel new];
			[self.contentView addSubview:_mLb_index];
		}
		_mLb_index.frame = CGRectMake(0,0,50,self.bounds.size.height);
		_mLb_index.textColor =  style.textColor;
		_mLb_index.textAlignment = NSTextAlignmentCenter;
		_mLb_index.text = model.index;
	}
	
	{
		if(!_mLb_title) {
			_mLb_title = [UILabel new];
			[self.contentView addSubview:_mLb_title];
//			_mLb_title.backgroundColor = [UIColor redColor];
		}
		int x = _mLb_index.frame.origin.x + _mLb_index.frame.size.width;
		int w = self.frame.size.width - x;
		int h =  [JsGeometryManager sizeForMultiLineStringWithContext:mModel.title font:style.titleFont maxWidth:self.mLb_title.frame.size.width].height;
		_mLb_title.frame = CGRectMake(x,padding,w,h);
		_mLb_title.textColor = style.textColor;
		_mLb_title.font = style.titleFont;
		_mLb_title.text = model.title;
	}
	
	{
		if(!_mLb_detail) {
			_mLb_detail = [UILabel new];
//			_mLb_detail.backgroundColor = [UIColor greenColor];
			[self.contentView addSubview:_mLb_detail];
		}
		int x = _mLb_title.frame.origin.x;
		int h = [JsGeometryManager sizeForMultiLineStringWithContext:mModel.desc font:style.detailFont maxWidth:self.mLb_detail.frame.size.width].height;
		int y = _mLb_title.frame.size.height + _mLb_title.frame.origin.y + padding;
		int w = _mLb_title.frame.size.width;
		_mLb_detail.text = model.desc;
		
		_mLb_detail.frame = CGRectMake(x,y,w,h);
		_mLb_detail.textColor =  style.textColor;
		_mLb_detail.font = style.detailFont;
	}
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
	[super setSelected:selected animated:animated];
	
		// Configure the view for the selected state
}

-(void)displayContent:(NSArray <NSString *>*)arr {
	if(arr.count < 3) {
		return;
	}
	NSString * str_index = arr[0];
	NSString * str_title = arr[1];
	NSString * str_detail = arr[2];
	self.mLb_index.text = str_index;
	self.mLb_title.text = str_title;
	self.mLb_detail.text = str_detail;
}

-(void)displayModel:(JsTvcLllModel *)model {
	mModel = model;
	self.mLb_index.text = model.index;
	self.mLb_title.text = model.title;
	self.mLb_detail.text = model.desc;
	[self setupUi:model];
}

@end
